package com.hjm.ui.shopcart;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.hjm.ui.R;

public class ShopCartBottomControl extends LinearLayout {
    private static final String TAG = "ShopCartBottomControl";
    private Listener listener;
    private CheckBox selectAllCheckBox;
    private TextView totalMoneyTextView,doneTextView;
    public ShopCartBottomControl(Context context) {
        super(context);
        init();
    }

    public ShopCartBottomControl(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
//        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Cell);
//        String text = a.getString(R.styleable.Cell_cellText);
//        if (text != null) {
//        }
    }

    public ShopCartBottomControl(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        // 在这里添加你的布局和逻辑
        LayoutInflater.from(getContext()).inflate(R.layout.layout_shop_cart_bottom_control, this, true);
        selectAllCheckBox = findViewById(R.id.check_box_shop_cart_select_all);
        totalMoneyTextView = findViewById(R.id.text_view_shop_cart_total_money);
        doneTextView = findViewById(R.id.text_view_shop_cart_done);

        selectAllCheckBox.setOnClickListener(v -> {
            listener.onSelectAllChanged(selectAllCheckBox.isChecked());
        });
        doneTextView.setOnClickListener(v -> {
            listener.onDoneClick();
        });
    }

    public void setListener(Listener listener) {
        this.listener = listener;
    }

    public void setTotalMoney(String totalMoney){
        Log.d(TAG, "setTotalMoney: 设置金额 "+totalMoney);
        totalMoneyTextView.setText(totalMoney);
    }

    public interface Listener {
        /**
         * 购物车底部控制栏——选择全部商品
         * @param isSelectAll
         */
        void onSelectAllChanged(boolean isSelectAll);

        /**
         * 购物车底部控制栏——完成
         */
        void onDoneClick();
    }
}
